
package tools;



import java.io.BufferedInputStream;
 import java.io.FileInputStream;
 import java.util.StringTokenizer;



















 public class StringUtil
         {

    public static String getLeftPaddedStr(String in, char padchar, int length) {
        /*  27 */
        StringBuilder builder = new StringBuilder(length);
        /*  28 */
        for (int x = (in.getBytes()).length; x < length; x++) {
            /*  29 */
            builder.append(padchar);

        }
        /*  31 */
        builder.append(in);
        /*  32 */
        return builder.toString();

    }













    public static String getRightPaddedStr(int in, char padchar, int length) {
        /*  46 */
        return getRightPaddedStr(String.valueOf(in), padchar, length);

    }



    public static String getRightPaddedStr(long in, char padchar, int length) {
        /*  50 */
        return getRightPaddedStr(String.valueOf(in), padchar, length);

    }



    public static String getRightPaddedStr(String in, char padchar, int length) {
        /*  54 */
        StringBuilder builder = new StringBuilder(in);
        /*  55 */
        for (int x = (in.getBytes()).length; x < length; x++) {
            /*  56 */
            builder.append(padchar);

        }
        /*  58 */
        return builder.toString();

    }












    public static String joinStringFrom(String[] arr, int start) {
        /*  71 */
        return joinStringFrom(arr, start, " ");

    }












    public static String joinStringFrom(String[] arr, int start, String sep) {
        /*  84 */
        StringBuilder builder = new StringBuilder();
        /*  85 */
        for (int i = start; i < arr.length; i++) {
            /*  86 */
            builder.append(arr[i]);
            /*  87 */
            if (i != arr.length - 1) {
                /*  88 */
                builder.append(sep);

            }

        }
        /*  91 */
        return builder.toString();

    }









    public static String makeEnumHumanReadable(String enumName) {
        /* 101 */
        StringBuilder builder = new StringBuilder(enumName.length() + 1);
        /* 102 */
        for (String word : enumName.split("_")) {
            /* 103 */
            if (word.length() <= 2) {
                /* 104 */
                builder.append(word);

            } else {
                /* 106 */
                builder.append(word.charAt(0));
                /* 107 */
                builder.append(word.substring(1).toLowerCase());

            }
            /* 109 */
            builder.append(' ');

        }
        /* 111 */
        return builder.substring(0, enumName.length());

    }















    public static int countCharacters(String str, char chr) {
        /* 127 */
        int ret = 0;
        /* 128 */
        for (int i = 0; i < str.length(); i++) {
            /* 129 */
            if (str.charAt(i) == chr) {
                /* 130 */
                ret++;

            }

        }
        /* 133 */
        return ret;

    }



    public static String getReadableMillis(long startMillis, long endMillis) {
        /* 137 */
        StringBuilder sb = new StringBuilder();
        /* 138 */
        double elapsedSeconds = (endMillis - startMillis) / 1000.0D;
        /* 139 */
        int elapsedSecs = (int) elapsedSeconds % 60;
        /* 140 */
        int elapsedMinutes = (int) (elapsedSeconds / 60.0D);
        /* 141 */
        int elapsedMins = elapsedMinutes % 60;
        /* 142 */
        int elapsedHrs = elapsedMinutes / 60;
        /* 143 */
        int elapsedHours = elapsedHrs % 24;
        /* 144 */
        int elapsedDays = elapsedHrs / 24;
        /* 145 */
        if (elapsedDays > 0) {
            /* 146 */
            boolean mins = (elapsedHours > 0);
            /* 147 */
            sb.append(getLeftPaddedStr(String.valueOf(elapsedDays), '0', 2));
            /* 148 */
            sb.append("天");
            /* 149 */
            if (mins) {
                /* 150 */
                boolean secs = (elapsedMins > 0);
                /* 151 */
                sb.append(getLeftPaddedStr(String.valueOf(elapsedHours), '0', 2));
                /* 152 */
                sb.append("时");
                /* 153 */
                if (secs) {
                    /* 154 */
                    boolean millis = (elapsedSecs > 0);
                    /* 155 */
                    sb.append(getLeftPaddedStr(String.valueOf(elapsedMins), '0', 2));
                    /* 156 */
                    sb.append("分");
                    /* 157 */
                    if (millis) {
                        /* 158 */
                        sb.append(getLeftPaddedStr(String.valueOf(elapsedSecs), '0', 2));
                        /* 159 */
                        sb.append("秒");

                    }

                }

            }
            /* 163 */
        } else if (elapsedHours > 0) {
            /* 164 */
            boolean mins = (elapsedMins > 0);
            /* 165 */
            sb.append(getLeftPaddedStr(String.valueOf(elapsedHours), '0', 2));
            /* 166 */
            sb.append("时");
            /* 167 */
            if (mins) {
                /* 168 */
                boolean secs = (elapsedSecs > 0);
                /* 169 */
                sb.append(getLeftPaddedStr(String.valueOf(elapsedMins), '0', 2));
                /* 170 */
                sb.append("分");
                /* 171 */
                if (secs) {
                    /* 172 */
                    sb.append(getLeftPaddedStr(String.valueOf(elapsedSecs), '0', 2));
                    /* 173 */
                    sb.append("秒");

                }

            }
            /* 176 */
        } else if (elapsedMinutes > 0) {
            /* 177 */
            boolean secs = (elapsedSecs > 0);
            /* 178 */
            sb.append(getLeftPaddedStr(String.valueOf(elapsedMins), '0', 2));
            /* 179 */
            sb.append("分");
            /* 180 */
            if (secs) {
                /* 181 */
                sb.append(getLeftPaddedStr(String.valueOf(elapsedSecs), '0', 2));
                /* 182 */
                sb.append("秒");

            }
            /* 184 */
        } else if (elapsedSeconds > 0.0D) {
            /* 185 */
            sb.append(getLeftPaddedStr(String.valueOf(elapsedSecs), '0', 2));
            /* 186 */
            sb.append("秒");

        } else {
            /* 188 */
            sb.append("None.");

        }
        /* 190 */
        return sb.toString();

    }



    public static int[] StringtoInt(String str, String separator) {
        /* 194 */
        StringTokenizer strTokens = new StringTokenizer(str, separator);
        /* 195 */
        int[] strArray = new int[strTokens.countTokens()];
        /* 196 */
        int i = 0;
        /* 197 */
        while (strTokens.hasMoreTokens()) {
            /* 198 */
            strArray[i] = Integer.parseInt(strTokens.nextToken().trim());
            /* 199 */
            i++;

        }
        /* 201 */
        return strArray;

    }



    public static boolean[] StringtoBoolean(String str, String separator) {
        /* 205 */
        StringTokenizer strTokens = new StringTokenizer(str, separator);
        /* 206 */
        boolean[] strArray = new boolean[strTokens.countTokens()];
        /* 207 */
        int i = 0;
        /* 208 */
        while (strTokens.hasMoreTokens()) {
            /* 209 */
            strArray[i] = Boolean.parseBoolean(strTokens.nextToken().trim());
            /* 210 */
            i++;

        }
        /* 212 */
        return strArray;

    }



    public static boolean isNumber(String str) {
        /* 216 */
        return str.matches("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$");

    }










    public static String codeString(String fileName) throws Exception {
        BufferedInputStream bin = new BufferedInputStream(
                new FileInputStream(fileName));
        int p = (bin.read() << 8) + bin.read();
        String code;
        //其中的 0xefbb、0xfffe、0xfeff、0x5c75这些都是这个文件的前面两个字节的16进制数
        switch (p) {
            case 0xefbb:
                code = "UTF-8";
                break;
            case 0xfffe:
                code = "Unicode";
                break;
            case 0xfeff:
                code = "UTF-16BE";
                break;
            case 0x5c75:
                code = "ANSI|ASCII";
                break;
            default:
                code = "GBK";
        }

        return code;
    }

}


/* Location:              C:\PGX\Server.jar!\tools\StringUtil.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */